package org.springboot.sample.controller;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springboot.sample.entity.User;
import org.springboot.sample.mapper.UserMapper;
import org.springboot.sample.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserController {
	private static final Logger logger = LoggerFactory.getLogger(UserController.class);
	
	@Autowired
	private UserService userService;
	
	@Autowired
	private UserMapper userMapper;
	
//	@Autowired
//	private IUserDao userDao;
	
	@RequestMapping("/list")
	public List<User> getUsers(){
		logger.debug("get users.");
		return userService.getUsers();
	}
	
//	@RequestMapping("/listjpa")
//	public List<org.springboot.sample.entity.jpa.User> getUserJpa(){
//		logger.info("通过JPA查询用户");
//		return userDao.getUsers();
//	}
	@RequestMapping("/likename")
	public List<User> likeName(@RequestParam String name){
		logger.info("mybatis likename...");
		List<User> l = userMapper.likeName(name);
		logger.info("likename:"+l);
		return l;
	}
	
	@RequestMapping("/{id}")
	public User getById(@PathVariable String id){
		logger.info("get user by id = "+id);
		User u = userMapper.getById(id);
		logger.info("get by id :"+u);
		return u;
	}
	
	@RequestMapping("/getall")
	public List<User> getAll(){
		List<User> l = userMapper.getAll();
		logger.info("getall:"+l);
		return l;
	}
	@RequestMapping("/tmp")
	public List<User> getTmp(){
		return userService.getTmp();
	}
}
